#!/bin/bash

cd ../build

start_time=$(date +%s) # %s可以计算的是1970年以来的秒数

# Random vs sequential load
# AR
sync; echo 3 | sudo tee /proc/sys/vm/drop_caches
./read_cold -f ../db/dataset/amazon_reviews.txt -k 16 -v 64 -d ../ssd/db_ar_16 -m 7 -u -n 10000 -i 5 $* --change_level_load > ../evaluation/ar_16_llsm_seqload.txt
./read_cold -f ../db/dataset/amazon_reviews.txt -k 16 -v 64 -d ../ssd/db_ar_16 -m 8 -u -n 10000 -i 5 $* --change_level_load > ../evaluation/ar_16_baseline_seqload.txt

sync; echo 3 | sudo tee /proc/sys/vm/drop_caches
./read_cold -f ../db/dataset/amazon_reviews.txt -k 16 -v 64 -d ../ssd/db_ar_16_random -m 7 -u -n 10000 -i 5 $* --change_level_load > ../evaluation/ar_16_llsm_rdmload.txt
./read_cold -f ../db/dataset/amazon_reviews.txt -k 16 -v 64 -d ../ssd/db_ar_16_random -m 8 -u -n 10000 -i 5 $* --change_level_load > ../evaluation/ar_16_baseline_rdmload.txt

# OSM
#sync; echo 3 | sudo tee /proc/sys/vm/drop_caches
#./read_cold -f ../db/dataset/osm_ny.txt -k 16 -v 64 -d ../ssd/db_osm_16 -m 7 -u -n 10000 -i 5 $* --change_level_load > ../evaluation/osm_16_llsm_seqload.txt
#./read_cold -f ../db/dataset/osm_ny.txt -k 16 -v 64 -d ../ssd/db_osm_16 -m 7 -u -n 10000 -i 5 $* --change_level_load > ../evaluation/osm_16_llsm_seqload.txt
#./read_cold -f ../db/dataset/osm_ny.txt -k 16 -v 64 -d ../ssd/db_osm_16 -m 8 -u -n 10000 -i 5 $* --change_level_load > ../evaluation/osm_16_baseline_seqload.txt

#sync; echo 3 | sudo tee /proc/sys/vm/drop_caches
#./read_cold -f ../db/dataset/osm_ny.txt -k 16 -v 64 -d ../ssd/db_osm_16_random -m 7 -u -n 10000 -i 5 $* --change_level_load > ../evaluation/osm_16_llsm_rdmload.txt
#./read_cold -f ../db/dataset/osm_ny.txt -k 16 -v 64 -d ../ssd/db_osm_16_random -m 7 -u -n 10000 -i 5 $* --change_level_load > ../evaluation/osm_16_llsm_rdmload.txt
#./read_cold -f ../db/dataset/osm_ny.txt -k 16 -v 64 -d ../ssd/db_osm_16_random -m 8 -u -n 10000 -i 5 $* --change_level_load > ../evaluation/osm_16_baseline_rdmload.txt

# ali-index
sync; echo 3 | sudo tee /proc/sys/vm/drop_caches
./read_cold -f ../db/dataset/idf_all.txt -k 16 -v 64 -d ../ssd/db_idf_all_16 -m 7 -u -n 10000 -i 5 $* --change_level_load > ../evaluation/idf_all_16_llsm_seqload.txt
./read_cold -f ../db/dataset/idf_all.txt -k 16 -v 64 -d ../ssd/db_idf_all_16 -m 8 -u -n 10000 -i 5 $* --change_level_load > ../evaluation/idf_all_16_baseline_seqload.txt

sync; echo 3 | sudo tee /proc/sys/vm/drop_caches
./read_cold -f ../db/dataset/idf_all.txt -k 16 -v 64 -d ../ssd/db_idf_all_16_random -m 7 -u -n 10000 -i 5 $* --change_level_load > ../evaluation/idf_all_16_llsm_rdmload.txt
./read_cold -f ../db/dataset/idf_all.txt -k 16 -v 64 -d ../ssd/db_idf_all_16_random -m 8 -u -n 10000 -i 5 $* --change_level_load > ../evaluation/idf_all_16_baseline_rdmload.txt

cd ../learned-leveldb/
python ./scripts/collect_results.py 2 > ../evaluation/expr_load_order.txt
cat ../evaluation/expr_load_order.txt

end_time=$(date +%s)
cost_time=$((end_time-start_time))
echo "build kernel time is $((cost_time/60))min $((cost_time%60))s"